//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.come.npc;

import com.tool.ModerateTask.TaskMixDeal;
import com.tool.ModerateTask.TaskProgress;
import com.tool.image.ImageMixDeal;
import come.tool.FightingData.FightingForesee;
import java.util.ArrayList;
import java.util.List;
import org.come.Frame.NPCJfram;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.NPCJpanel;
import org.come.action.NpcMenuAction;
import org.come.bean.RoleShow;
import org.come.control.JirenjiaobenchuliControl;
import org.come.model.Robots;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.thread.AutoTaskTimeControlRunnable;
import org.come.thread.TimeControlRunnable;
import org.come.until.GsonUtil;
import org.come.until.SplitStringTool;
import org.come.until.UserMessUntil;
import org.come.until.Util;

public class Creeps implements NpcMenuAction {
	public Creeps() {
	}

	@Override
    public void menuControl(String type) {
		if (type.startsWith("我是来击杀你的")) {
			NPCJpanel npcJpanel = NPCJfram.getNpcJfram().getNpcjpanel();
			if (npcJpanel.getTaskMonster() != null) {
				if (TaskMixDeal.istrigger(0, npcJpanel.getTaskMonster())) {
					taskGuai(UserMessUntil.getRobot(String.valueOf(npcJpanel.getTaskMonster().getDId())), npcJpanel.getTaskMonster().getDName(), getND(type));
				}
			} else if (npcJpanel.getNpcInfoBean() != null) {
				String binding = npcJpanel.getNpcInfoBean().getNpctable().getBinding();
				if (binding != null && !"".equals(binding) && TaskMixDeal.istrigger(Integer.parseInt(npcJpanel.getNpcInfoBean().getNpctable().getNpcid()), (TaskProgress)null)) {
					taskGuai(UserMessUntil.getRobot(binding), npcJpanel.getNpcInfoBean().getNpctable().getNpcname(), getND(type));
				}
			}
		} else if ("满地宝物先抢一个在说".equals(type) || "我是来劫道的".equals(type) || "攻击".equals(type)) {
			this.Minglei();
//			if (!this.Minglei()) {
//				TimeControlRunnable.addAllTask(null);
//			}
		}

	}
	public boolean Minglei() {
		RoleShow roleShow = ImageMixDeal.userimg.getRoleShow();
		// 判断是否在战斗
		if (roleShow.getFighting() == 0) {
			NPCJpanel npcJpanel = NPCJfram.getNpcJfram().getNpcjpanel();
			if (npcJpanel.getMapMonsterBean().getType() != 0) {
				ZhuFrame.getZhuJpanel().addPrompt2("怪物正在忙碌中");
			} else {
				FightingForesee fightingForesee = new FightingForesee();
				fightingForesee.setType(1);
				int robotid = npcJpanel.getMapMonsterBean().getRobotid();
				//TODO 是否允许多人参与，type=4不带伙伴
				if (robotid == 651 || robotid == 1048) {//1048为宝图强盗指定 ，651是灵猴
					if (roleShow.getTeam().split("\\|").length > 1) {
						ZhuFrame.getZhuJpanel().addPrompt2("只能单人击杀");
						return false;
					}
					fightingForesee.setType(4);
				}

				String team = roleShow.getTeam();
				if (team.split("\\|")[0].equals(roleShow.getRolename())) {
					fightingForesee.setI(npcJpanel.getMapMonsterBean().getI());
					fightingForesee.setYidui(team);
					roleShow.getPlayer_Paths().clear();
					String sendMes = Agreement.FightingForeseeAgreement(GsonUtil.getGsonUtil().getgson().toJson(fightingForesee));
					SendMessageUntil.toServer(sendMes);
					return true;
				}
			}
		}
		return false;
	}
	public static int getND(String type) {
		if (type.length() == 7) {
			return 0;
		} else {
			String ndString = type.substring(8, 10);
			return "困难".equals(ndString) ? 1 : ("卓越".equals(ndString) ? 2 : ("地狱".equals(ndString) ? 3 : 4));
		}
	}

	public static void taskGuai(Robots robots, String name, int nd) {
		if (robots != null && ImageMixDeal.userimg.getRoleShow().getFighting() == 0) {
			String team = ImageMixDeal.userimg.getRoleShow().getTeam();
			if (team.split("\\|")[0].equals(ImageMixDeal.userimg.getRoleShow().getRolename())||team.split("\\|")[0].equals(JirenjiaobenchuliControl.name)) {
				ImageMixDeal.userimg.getRoleShow().getPlayer_Paths().clear();
				FightingForesee fightingForesee = new FightingForesee();
				fightingForesee.setYidui(team);
				fightingForesee.setAlias(name);
				fightingForesee.setRobotid(robots.getRobotid());
				fightingForesee.setNd(nd);
				fightingForesee.setType(2);
				String sendMes = Agreement.FightingForeseeAgreement(GsonUtil.getGsonUtil().getgson().toJson(fightingForesee));
				SendMessageUntil.toServer(sendMes);
			}
		}
	}



	public static void yeguai() {
		if (ImageMixDeal.userimg.getRoleShow().getFighting() == 0 && AutoTaskTimeControlRunnable.isIsAutoTask() == false) {
			FightingForesee fightingForesee = new FightingForesee();
			String team = ImageMixDeal.userimg.getRoleShow().getTeam();
			if (team.split("\\|")[0].equals(ImageMixDeal.userimg.getRoleShow().getRolename())) {
				fightingForesee.setYidui(team);
				fightingForesee.setCreepids(geListMoster(Util.mapmodel.getGamemap().getMonster(), fightingForesee.getYidui().split("\\|").length));

				try {
					fightingForesee.setType(0);
					ImageMixDeal.userimg.getRoleShow().getPlayer_Paths().clear();
					String sendMes = Agreement.FightingForeseeAgreement(GsonUtil.getGsonUtil().getgson().toJson(fightingForesee));
					SendMessageUntil.toServer(sendMes);
				} catch (Exception var3) {
				}
			}
		}
	}

	public static void getfight(int type) {
		if (ImageMixDeal.userimg.getRoleShow().getFighting() == 0) {
			FightingForesee fightingForesee = new FightingForesee();
			if (ImageMixDeal.userimg.getRoleShow().getTeamInfo() != null && !"".equals(ImageMixDeal.userimg.getRoleShow().getTeamInfo())) {
				fightingForesee.setYidui(ImageMixDeal.userimg.getRoleShow().getTeamInfo());
			} else {
				fightingForesee.setYidui(ImageMixDeal.userimg.getRoleShow().getRolename());
			}

			try {
				fightingForesee.setType(type);
				ImageMixDeal.userimg.getRoleShow().getPlayer_Paths().clear();
				String sendMes = Agreement.FightingForeseeAgreement(GsonUtil.getGsonUtil().getgson().toJson(fightingForesee));
				SendMessageUntil.toServer(sendMes);
			} catch (Exception var3) {
				var3.printStackTrace();
			}

		}
	}

	public static List<String> geListMoster(String monsterStr, int playerNum) {
        List<String> monsters = new ArrayList<>();
        List<String> monsterList = SplitStringTool.splitString(monsterStr);

        for(int i = 0; i < 10; ++i) {
        	if (i > playerNum && Util.random.nextInt(2) == 1) {
				break;
			}
            monsters.add((String)monsterList.get(Util.random.nextInt(monsterList.size())));
        }

        return monsters;
	}
}
